﻿@{
    ViewBag.Title = "送货单列表";
    Layout = "~/Views/Shared/_LayoutList.cshtml"; 
}
@(       
 Html.nbGridFor<MaterialDelivery>(s =>
 {
     s.Action("List");
     s.ExtParam(new { date = DateTime.Today.AddDays(1) });
     s.Columns(c =>
     {
         c.Bind(e => e.Id).IsKey();
         c.BindDateTime(e => e.Date).Width(70).AsSearch();
         c.BindDateTime(e => e.OrderDate).Width(70).AsSearch();
         c.Bind(e => e.SiteName).Width(50).AsQuery().AsSearch();
         c.Bind(e => e.TotalWeight).Width(40).Align(GridAlign.Right).AsSearch();
         c.Bind(e => e.TotalAmount).Width(40).Align(GridAlign.Right).AsSearch();
         c.BindEnum(e => e.State, "DishState").Width(30);
         c.Bind(e => e.ItemDesc).Width("auto").Align(GridAlign.Left).AsSearch().AsQuery();
         //c.Bind(e => e.Address).Width(140).Align(GridAlign.Left).AsQuery().AsSearch();
         //c.Bind(e => e.UpdateUser).Width(60);
         c.BindDateTime(e => e.UpdateDate).Width(70);
         c.BindTemplate(260)
            .Template(@<a href="@Url.Action("Export")?id=${Id}" target="_blank" class="imgbtn2"><span
                class="print">打印</span></a>)
            .Template(@<a href="javascript:DeliveryItem('${Id}','${State}','${SiteName}')" class="imgbtn2"><span
                class="accept">送货</span></a>)
            .Template(@<a href="javascript:SignItem('${Id}','${State}','${SiteName}')" class="imgbtn2"><span
                class="accept">签收</span></a>)
            .Template(Url.GridRowEditLink("编辑送货单"))
            .Template(@<a href="javascript:DeleteItem('${Id}','${State}')" class="imgbtn2"><span
                class="Delete">删除</span></a>);


     });
     s.Buttons(b =>
     {
         b.Bind(GridButtonType.Add);
     });
 }))
<script type="text/javascript">
    function DeleteItem(id, state) {
        if (state != "Draft") {
            alert("送货单状态已经不是草稿了，不能删除！");
        }
        else {
            DeleteRecord('@Url.Action("Delete")?id=' + id, "该送货单")
        }
    }
    function SignItem(id, state, site) {
        if (state != "Delivery") {
            alert("送货单状态不是送货，不能签收！");
        }
        else {
            OpenModalDialog('@Url.Action("Sign")?Id=' + id,
            {
                caption: "签收单（" + site + "）",
                width: 610,
                height: 450,
                onclose: refreshGrid
            });
        }
    }
    function DeliveryItem(id, state, site) {
        if (state != "Draft") {
            alert("送货单状态不是草稿，不能送货！");
        }
        else {
            ajaxTodo('@Url.Action("Delivery")', { Id: id }, ajaxCallBack, "您确认需要向项目点（" + site + "）送货?");
        }
    }
</script>
